package com.bkhech.spring.security.example.controller;

import com.bkhech.spring.security.example.domain.AuthLoginRespVo;
import com.bkhech.spring.security.example.domain.CommonResult;
import com.bkhech.spring.security.example.service.AuthService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.security.PermitAll;

/**
 * @author guowm
 * @date 2023/1/10
 */
@RequiredArgsConstructor
@RestController
public class AuthController {

    final AuthService authService;
    final PasswordEncoder passwordEncoder;

    @PostMapping("/login")
    @PermitAll
    @ApiOperation("使用账号密码登录")
    public CommonResult<AuthLoginRespVo> login(String name, String passwd) {
        final AuthLoginRespVo authLoginRespVo = authService.login(name, passwd);
        return CommonResult.success(authLoginRespVo);
    }

}
